#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
	int y = 0;
	int m = 0;
	int arr1[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
	int arr2[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
	int ret = 0;
	while (scanf("%d %d", &y, &m) != -1)
	{
		if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
		{
			ret = arr1[m - 1];
		}
		else
		{
			ret = arr2[m - 1];
		}
		printf("%d\n", ret);
	}
	return 0;
}